<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="企业名称/用户真名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入企业名称/用户真名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="auditTime">
        <el-date-picker
          v-model="auditTimeRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="审核时间" prop="auditTime">
        <el-date-picker clearable
          v-model="queryParams.auditTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['backend:real_auth:add']"
        >新增</el-button>
      </el-col>-->
      <!--      <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['backend:real_auth:edit']"
              >修改</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['backend:real_auth:remove']"
              >删除</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['backend:real_auth:export']"
              >导出</el-button>
            </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="real_authList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="表格id" align="center" prop="id" />-->
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="企业名称/用户真名" align="center" prop="realName" />
      <el-table-column label="统一社会信用代码" align="center" prop="socialReditCode" />
      <el-table-column label="个人/法人手机号码" align="center" prop="legalMobile" />
      <el-table-column label="个人/企业法人身份证正面" align="center" prop="idCardFront" />
      <el-table-column label="个人/企业法人身份证反面" align="center" prop="idCardBack" />
      <el-table-column label="个人身份证号码" align="center" prop="idCardNum" />
      <el-table-column label="营业执照" align="center" prop="businessCer" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber" />
      <el-table-column label="开户行" align="center" prop="bankOfDeposit" />
      <el-table-column label="认证状态" align="center" prop="realStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.real_status" :value="scope.row.realStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="认证类型" align="center" prop="realType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_type" :value="scope.row.realType"/>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="auditBy" />
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.realStatus == 1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAudit(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改实名认证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" disabled />
        </el-form-item>
        <el-form-item label="企业名称/用户真名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入企业名称/用户真名" disabled />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="socialReditCode">
          <el-input v-model="form.socialReditCode" placeholder="请输入统一社会信用代码" disabled />
        </el-form-item>
        <el-form-item label="个人/法人手机号码" prop="legalMobile">
          <el-input v-model="form.legalMobile" placeholder="请输入个人/法人手机号码" disabled />
        </el-form-item>
        <el-form-item label="个人/企业法人身份证正面" prop="idCardFront">
          <el-input v-model="form.idCardFront" placeholder="请输入个人/企业法人身份证正面" disabled />
        </el-form-item>
        <el-form-item label="个人/企业法人身份证反面" prop="idCardBack">
          <el-input v-model="form.idCardBack" placeholder="请输入个人/企业法人身份证反面" disabled />
        </el-form-item>
        <el-form-item label="个人身份证号码" prop="idCardNum">
          <el-input v-model="form.idCardNum" placeholder="请输入个人身份证号码" disabled />
        </el-form-item>
        <el-form-item label="营业执照" prop="businessCer">
          <el-input v-model="form.businessCer" placeholder="请输入营业执照" disabled />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" disabled />
        </el-form-item>
        <el-form-item label="开户行" prop="bankOfDeposit">
          <el-input v-model="form.bankOfDeposit" placeholder="请输入开户行" disabled />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormForAuditPass">通过</el-button>
        <el-button type="danger" @click="submitFormForAuditNoPass">不通过</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listReal_auth,
  getReal_auth,
  delReal_auth,
  addReal_auth,
  updateReal_auth,
  auditRealAuth
} from "@/api/backend/real_auth"

export default {
  name: "Real_auth",
  dicts: ['real_status', 'user_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实名认证表格数据
      real_authList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 审核时间区间
      auditTimeRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        realName: null,
        socialReditCode: null,
        legalMobile: null,
        idCardFront: null,
        idCardBack: null,
        idCardNum: null,
        businessCer: null,
        bankCardNumber: null,
        bankOfDeposit: null,
        realStatus: null,
        realType: null,
        auditBy: null,
        auditTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询实名认证列表 */
    getList() {
      this.loading = true
      let range = this.addDateRange(this.queryParams, this.auditTimeRange, 'AuditTime');
      listReal_auth(range).then(response => {
        this.real_authList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        realName: null,
        socialReditCode: null,
        legalMobile: null,
        idCardFront: null,
        idCardBack: null,
        idCardNum: null,
        businessCer: null,
        bankCardNumber: null,
        bankOfDeposit: null,
        realStatus: null,
        realType: null,
        auditBy: null,
        auditTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.auditTimeRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 审核按钮操作 */
    handleAudit(row) {
      this.reset()
      const id = row.id || this.ids
      getReal_auth(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "实名认证审核"
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加实名认证"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getReal_auth(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改实名认证"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReal_auth(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addReal_auth(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 实名认证审核操作，审核通过 */
    submitFormForAuditPass() {
      this.form.realStatus = 2;
      auditRealAuth(this.form).then(response => {
        this.$modal.msgSuccess("审核成功");
        this.open = false;
        this.getList();
      })
    },
    /** 实名认证审核操作，审核不通过 */
    submitFormForAuditNoPass() {
      this.form.realStatus = 3;
      auditRealAuth(this.form).then(response => {
        this.$modal.msgSuccess("审核成功");
        this.open = false;
        this.getList();
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除实名认证编号为"' + ids + '"的数据项？').then(function() {
        return delReal_auth(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('backend/real_auth/export', {
        ...this.queryParams
      }, `real_auth_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
